<template>
  <el-container>
    <!-- <el-header>
      <home-header></home-header>
    </el-header> -->

    <div class="main">
      <div class="self-info">
        <avatar
          class="avatar"
          :size="120"
          style="font-size: 50px; line-height: 120px"
          :user="userData"
        ></avatar>
        <div class="brife-intro">
          <h2 class="username">{{ userData.nickname }}  (用户名:{{ userData.username }})    <i v-if="userInfo.gender == 1" style="color:var(--text-primary)" class="fa fa-mars" aria-hidden="true"></i> 
          <i v-if="userInfo.gender == 0" style="color:pink" class="fa fa-venus" aria-hidden="true"></i> </h2>
       
          <div class="counts-wrapper">
            <div class="counts">
              <span class="number">{{ userData.followingCount }}</span>
              <span class="catagory">关注</span>
            </div>
            <div class="counts">
              <span class="number">{{ userData.fansCount }}</span>
              <span class="catagory">粉丝</span>
            </div>
            <div class="counts">
              <span class="number">{{ userData.postCount }}</span>
              <span class="catagory">文章</span>
            </div>
            <div class="counts">
              <span class="number">{{ userData.likeCount }}</span>
              <span class="catagory">收获点赞</span>
            </div>
          </div>
          <p style="margin-top: 20px">{{ userData.intro }}</p>
        </div>
      </div>
      <div class="information">
        <div class="nav">
          <el-tabs :value="activeName" @tab-click="handleClick">
            <el-tab-pane v-if="isSelf" label="个人信息" name="self-info">
              <!-- <self-info></self-info> -->
              <router-view name="self-info"></router-view>
            </el-tab-pane>
            <!-- <el-tab-pane label="消息" name="second">
              <message-center></message-center>
            </el-tab-pane> -->
            <el-tab-pane label="文章" name="postList">
              <router-view name="postList"></router-view>
            </el-tab-pane>
            <el-tab-pane v-if="isSelf" label="收藏" name="collection">
              <router-view name="collection"></router-view>
            </el-tab-pane>

            <el-tab-pane v-if="isSelf" label="浏览历史记录" name="history">
              <router-view name="history"></router-view>
            </el-tab-pane>
            <el-tab-pane label="关注" name="followings">
              <router-view name="followings"></router-view>
            </el-tab-pane>
            <el-tab-pane label="粉丝" name="fans">
              <router-view name="fans"></router-view>
            </el-tab-pane>
            <el-tab-pane  v-if="isSelf" label="关注的板块" name="ForumsFollowed">
              <router-view name="ForumsFollowed"></router-view>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </div>
  </el-container>
</template>

<script>
import HomeHeader from "@/components/HomeItems/HomeHeader.vue";
import SelfInfo from "@/components/InfoCenterItems/SelfInfo.vue";
import CollectionList from "@/components/InfoCenterItems/CollectionList.vue";
import HistoryList from "@/components/InfoCenterItems/HistoryList.vue";
import FollowsList from "@/components/InfoCenterItems/FollowsList.vue";
import Avatar from "@/components/CommonItems/avatar.vue";
import { mapState } from "vuex";
import userApi from "@/axios/userApi";

export default {
  props: ["userId"],
  data() {
    return {
      activeName: "",
      userData: {},
      isSelf: false,
    };
  },
  components: {
    HomeHeader,
    SelfInfo,
    CollectionList,
    HistoryList,
    FollowsList,
    Avatar,
  },
  methods: {
    handleClick(e) {
      if (this.$route.name !== e.name) {
        this.$router.push({ name: e.name, params: { userId: this.userId } });
      }
    },
    fetch() {
      if (this.userId == this.userInfo.userId) {
        this.userData = this.userInfo;
        this.isSelf = true;
        return;
      }
      this.isSelf = false;
      userApi.getUser(this.userId).then(({ data }) => {
        this.userData = data.data;
      });
    },
  },
  watch: {
    $route: {
      immediate: true,
      handler(newV, oldV) {
        this.activeName = newV.name;
      },
    },
    userId() {
      this.fetch();
    },
  },
  computed: {
    ...mapState("user", { userInfo: "info", isLogin: "isLogin" }),
  },

  created() {
    this.fetch();
  },
};
</script>

<style scoped lang="less">
@import "@/assets/less/common.less";
.main {
  width: 900px;
  margin: 0 auto;
  margin-top: 40px;
}
.self-info {
  display: flex;
  .avatar {
    margin-right: 20px;
  }
  .username {
    margin-bottom: 10px;
  }
  .brief-intro {
    display: flex;
  }
  .counts-wrapper {
    display: flex;
  }
  .counts {
    display: flex;
    flex-direction: column;
    padding-right: 20px;
    &:not(:last-child) {
      border-right: 1px solid @borderBase;
    }
    &:not(:first-child) {
      padding-left: 20px;
    }
    .number {
      line-height: 30px;
    }
    .catagory {
      color: @regularText;
      font-size: 12px;
    }
  }
}
.information {
  margin-top: 50px;
}
</style>